<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<html:html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title></title>
		<style type="text/css" >
		.selectStyle{
		width:100px;
		}
		</style>
		<script language="javascript" src="/js/json2.js"></script>
		<script language="javascript" src="/js/litpen_ajax.js"></script>		
		<script language="javascript" type="text/javascript">
		//<![CDATA[
			function loadModule(){
				var module_ajax = new Ajax("/admin/showModulesAjax.do",null,true,loadModuleCallback,"get");
				module_ajax.send();
			}
			
			function loadAuthorizes(selectObj){
				var action = "/admin/showAuthorizeAjax.do" + "?mid=" + selectObj.value;
				var authorize_ajax = new Ajax(action,null,true,loadAuthorizeCallback,"get");
				authorize_ajax.send();
			}
			
			function loadModuleCallback(){
				var result = arguments[0];
				var myData = JSON.parse(result,null);
				var module_select = document.getElementById("moduleId");
				if (module_select){
					module_select.innerHTML = "";
					for (var i = 0;i<myData.modules.length;i++){
						var option = document.createElement("option");
						option.setAttribute("value",myData.modules[i].mid);
						
						option.text= myData.modules[i].moduleName;
						module_select.add(option);
					}
				}
			}
			
			function loadAuthorizeCallback(){
				var result = arguments[0];
				if (result =="")
					return;
				var myData = JSON.parse(result,null);
				
				var authorize_list = document.getElementById("from");
				alert(authorize_list);
				if (authorize_list){
					
					authorize_list.innerHTML = "";
					for (var i = 0;i<myData.authorizes.length;i++){
						var option = document.createElement("option");
						option.setAttribute("value",myData.authorizes[i].tag);
						option.text= myData.authorizes[i].authorizeName;
						
						authorize_list.add(option);
					}
				}
			}
			
			
			function copyToList(from,to){
				fromList = eval('document.forms[0].' + from);
				toList = eval('document.forms[0].' + to);
				if (toList.options.length > 0 && toList.options[0].value == 'temp'){
					toList.options.length = 0;
				}
				var sel = false;
				for (i=0;i<fromList.options.length;i++){
					var current = fromList.options[i];
					if (current.selected){
						sel = true;
						if (current.value == 'temp'){
							alert ('你不能选择这个项目!');
							return;
						}
						txt = current.text;
						val = current.value;
						toList.options[toList.length] = new Option(txt,val);
						
						fromList.options[i] = null;
						i--;
					}
				}
				if (!sel) alert ('你还没有选择任何项目');
			}
			function copyAll(from,to){
				fromList = eval('document.forms[0].' + from);
				toList = eval('document.forms[0].' + to);
				if (toList.options.length > 0 && toList.options[0].value == 'temp'){
					toList.options.length = 0;
				}
				for (i=0;i<fromList.options.length;i++){
					var current = fromList.options[i];
					if (current.value == 'temp'){
							alert ('你不能选择这个项目!');
							return;
					}
					txt = current.text;
					val = current.value;
					toList.options[toList.length] = new Option(txt,val);
					fromList.options[i] = null;
					i--;
				}
			}
			
			function groupAuthorizeInit(form){
				var str = "";
				for (var i=0;i<form.to.length;i++){
					str += form.to[i].value + "/";
				}
				form.groupAuthorize.value= str;
				alert(form.groupAuthorize.value);
			}
		//]]>
		</script>
	</head>
	<body onLoad="loadModule();">
		<html:form method="POST" action="/admin/addGroup" onsubmit="groupAuthorizeInit(this);">
			权限组名称：<html:text name="GroupForm" property="groupName"/><br/>
			<html:hidden name="GroupForm" property="groupAuthorize"/>
			权限组所属模块：<html:select name="GroupForm" property="moduleId" styleId="moduleId" onchange="loadAuthorizes(this)">
			
			</html:select><br/>
			<html:submit></html:submit>
			<table>
				<tr>
				<td>
			<select size="10"  multiple name="from" class="selectStyle" id="from"  >
			
		  </select>
		</td>
		<td><button onClick="copyAll('from','to');">->></button><br/>
		<button onClick="copyToList('from','to');">--></button><br/>
		<button onClick="copyToList('to','from');"><--</button><br/>
		<button onClick="copyAll('to','from');"><<-</button>
		</td>
		<td>
		<select size="10"  multiple name="to" class="selectStyle">
			
		  </select>
		</td>
		</tr>
		</table>
		</html:form>
	</body>
</html:html>
